package com.badger.generator.constant;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;

/**
 * 统一返回的类型
 * @author liqi
 */
@Getter
@Setter
public class Result implements Serializable {

    private static final long serialVersionUID = -773630722718841243L;

    /**失败的消息代码.*/
    private String status;

    /**返回的对象*/
    private Object value;

    private Result(String status, Object value) {
        this.value = value;
        this.status = status;
    }

    public static Result getInstance(String status, Object value) {
        return new Result(status, value);
    }

    public static Result getInstance() {
        return getInstance(null);
    }

    public static Result getInstance(Object value) {
        return getInstance(MesssageSatus.SUCCESS.getMessage(), value);
    }

    public enum MesssageSatus {
        /**正常访问.*/
        SUCCESS("200", "正常访问"),
        /**系统异常.*/
        ERROR_1001("1001", "系统异常,请联系管理员"),
        /***/
        ERROR_1002("1002", "没有访问权限"),
        /**登录超时.*/
        ERROR_1003("1003", "登录超时,或用户未登录！"),
        /**请求参数异常.*/
        ERROR_1004("1004", "请求参数异常"),
        /**请求参数异常.*/
        ERROR_1005("1005", "核对设备类型编码以及企业id"),
        /**用户名或者密码错.*/
        ERROR_1006("1006", "用户名或者密码错误");

        public static Map<String, String> MESSSAGE_SATUS_MAP = new HashMap<>();

        static {
            MesssageSatus[] values = MesssageSatus.values();
            for (MesssageSatus messsageSatus : values) {
                MESSSAGE_SATUS_MAP.put(messsageSatus.getStatus(), messsageSatus.getMessage());
            }
        }
        @Getter
        private String status;
        @Getter
        private String message;

        private MesssageSatus(String status, String message) {
            this.status = status;
            this.message = message;
        }
    }
}
